<?php
session_start();
    if(!isset($_SESSION['pwd']) || empty($_SESSION['pwd']))
    {
        header("Location: login.php"); 
        exit;
    }
if(isset($_REQUEST['onsub'])){
    if( $_REQUEST['onsub']=='ok')
    {
          //require_once dirname(__FILE__) . '/../includes/common.inc.php';
          require_once dirname(__FILE__) . '/../includes/data.cfg.php';
          require_once dirname(__FILE__) . '/../includes/pdoorm.inc.php';
        
          $export_name = BRANCH.$_REQUEST['begin_date'].'--'.$_REQUEST['end_date'].'expense';
          header("Content-type:application/vnd.ms-excel");
          header("Content-Disposition:attachment;filename=$export_name.xls");
        
        
          //require_once dirname(__FILE__) . '/includes/pdoorm.inc.php';
          
          
          $sql="select expense_date, create_date,expense_payee,expense_particulars,expense_cash,expense_noncash,expense_note from expense where expense_date between '2010-01-01' and '2011-01-01'";
          $dataarr = getall($sql,1);
          echo"<table border='1'><tr>";
          echo " <td colspan='7' height='30px' align='center'><h1>".$export_name."</h1></td></tr><tr height='27' style='font-weight:bold;'>";
          echo   "<td>payDate</td>";
          echo   "<td>createdDate</td>";
          echo   "<td>payee</td>";
          echo   "<td>particular</td>";
          echo   "<td>cash</td>";
          echo   "<td>no-cash</td>";
          echo   "<td>note</td>";
          echo  "</tr>";  
        
          if(is_array($dataarr))
          {
            foreach ($dataarr as $dr)
            {
               echo" <tr>";        
               echo   "<td>".$dr['expense_date']."</td>";
               echo   "<td>".$dr['create_date']."</td>";
               echo   "<td>".$dr['expense_payee']."</td>";
               echo   "<td>".$dr['expense_particulars']."</td>";
               echo   "<td>".$dr['expense_cash']."</td>";
               echo   "<td>".$dr['expense_noncash']."</td>";
               echo   "<td>".$dr['expense_note']."</td>";
               echo  "</tr>";      
            }
          }
          echo"</table>";
          die;
    }

}
include 'header.php';
//header("Content-type: text/html; charset=utf-8");

?>
 <br>
 <div>
    <fieldset>
    <legend>Expense(Old System)</legend>
      <form action="<?php echo $_SERVER['PHP_SELF'];?>" method="POST">
        <label><span style="color:red;font-weight:bolder;">Date format:2010-01-01</span></label><br>
        <label>P/Date<input type="text" name ="begin_date" id="begin_date" value='2010-01-01' readonly></label><label> TO <input type="text" name ="end_date" id="end_date" value='2011-01-01' readonly></label>
        <label><input type="hidden" name="onsub" id="onsub"  value="ok">
        <input type="submit" value="download"></label>
      </form>
    </fieldset>
    </fieldset>
 </div>